BatteryLog, a tool to log battery usage

We are often asked about estimated battery life time.

As you know, this depends on a lots of settings and the environment. Inspired by Ronalds presentation/session called ‘Thinking green’ at an ITC developer conference and on request of partners I did a small app that will log battery status including device settings (radios activated).

As many devices are out in the field I included also logging to network using broadcasts (IT admins should forgive me). Together with the free netcat (which is identified as a virus/worm by some stupid virus scanners, BTW: same with tftp server apps on windows), you will get the log data over the net.
OK, here is the readme for the tool:

BatteryLog.exe

Version:
0.91

Purpose:
Periodically log battery status.
Logging is done into file batterylog.txt in the executable directory and via a boradcast into the network.
One can use netcat to get the broadcasts. The broadcast udp port used is 9998.

Usage:

batterylog.exe 1
starts logging for every second, battery life will be estimated with the default battery capacity of 4200mAh
batterylog.exe 1 2200
starts logging for every second, battery life will be estimated with a battery capacity of 2200mAh
batterylog.exe 1 2200 NOBCAST
starts logging for every second, battery life will be estimated with a battery capacity of 2200mAh;
no broadcast is send over the network
batterylog.exe kill
stops logging and application quits
quitting the application can also be forced with a file called _stop_battery_log.flag in windows directory
the application will quit after a maximum of the logging interval

agenda
ACLineStatus;
AC_LINE_OFFLINE 0x00
AC_LINE_ONLINE 0x01
AC_LINE_BACKUP_POWER 0x02
AC_LINE_UNKNOWN 0xFF

BatteryFlag;
BATTERY_FLAG_HIGH 0x01
BATTERY_FLAG_LOW 0x02
BATTERY_FLAG_CRITICAL 0x04
BATTERY_FLAG_CHARGING 0x08
BATTERY_FLAG_NO_BATTERY 0x80
BATTERY_FLAG_UNKNOWN 0xFF
BatteryLifePercent;
Percentage of full battery charge remaining. Must be in the range 0 to 100, or BATTERY_PERCENTAGE_UNKNOWN
BackupBatteryFlag;
BATTERY_FLAG_HIGH 0x01
BATTERY_FLAG_LOW 0x02
BATTERY_FLAG_CRITICAL 0x04
BATTERY_FLAG_CHARGING 0x08
BATTERY_FLAG_NO_BATTERY 0x80
BATTERY_FLAG_UNKNOWN 0xFF
BackupBatteryLifePercent;
Percentage of full battery charge remaining. Must be in the range 0 to 100, or BATTERY_PERCENTAGE_UNKNOWN

BATTERY_PERCENTAGE_UNKNOWN 0xFF
BATTERY_LIFE_UNKNOWN 0xFFFFFFFF

BatteryVoltage; // Reports Reading of battery voltage in millivolts (0..65535 mV)
BatteryCurrent; // Reports Instantaneous current drain (mA). 0..32767 for charge, 0 to -32768 for discharge
BatteryAverageCurrent; // Reports short term average of device current drain (mA). 0..32767 for charge, 0 to -32768 for discharge
BatteryAverageInterval; // Reports time constant (mS) of integration used in reporting BatteryAverageCurrent
BatterymAHourConsumed; // Reports long-term cumulative average DISCHARGE (mAH). Reset by charging or changing the batteries. 0 to 32767 mAH
BatteryTemperature; // Reports Battery temp in 0.1 degree C (-3276.8 to 3276.7 degrees C)
BackupBatteryVoltage; // Reports Reading of backup battery voltage

wifi
current wifi status: 0=off, 1=on, other unknown or unsupported
phone
current phone status: 0=off, 1=on, other unknown or unsupported
BT
current BT status: 0=off, 1=on, other unknown or unsupported
bkl
current backlight level, = step level, ie 5 on CN3 means maximum
BKL stat
current backlight status, 0=off, 1=on, others=unknown

Here is a sample log:

Date Time ACLineStatus BatteryFlag BatteryLifePercent BackupBatteryFlag BackupBatteryLifePercent BatteryVoltage BatteryCurrent BatteryAverageCurrent BatteryAverageInterval BatterymAHourConsumed BatteryTemperature BackupBatteryVoltage estimated BattLife(for 4000 mAh)
02.06.2005 04:52:47 0001 0008 0100 0009 0100 4198 729 729 5120 0 340 2317 05:29
02.06.2005 04:53:09 0001 0008 0100 0009 0100 4198 725 725 5120 0 340 2319 03:02
02.06.2005 04:53:22 0001 0008 0100 0009 0100 4198 722 722 5120 0 340 2318 03:02
02.06.2005 04:53:47 0001 0008 0100 0009 0100 4198 717 717 5120 0 340 2319 05:34
02.06.2005 04:54:09 0001 0008 0100 0009 0100 4198 714 714 5120 0 340 2318 03:04
02.06.2005 04:54:22 0001 0008 0100 0009 0100 4198 710 710 5120 0 340 2318 03:05

The file is tab delimitted and can be easily load into a spreadsheet app and then you can do nice graphics:

batterylog

And here the broadcast catched by netcat (on Windows PC):

D:\>nc -lup 999832110646073: 04.06.2005 00:22:50 0001 0008 0100 0009 0100 4204 186 186 5120 0 310 2314 21:30 1 0 0 5 132110646073: 04.06.2005 00:22:52 0001 0008 0100 0009 0100 4204 186 186 5120 0 310 2315 21:30 1 0 0 5 132110646073: 04.06.2005 00:22:55 0001 0008 0100 0009 0100 4204 185 185 5120 0 310 2315 21:37 1 0 0 5 1

I am using itsutils to start apps remotely on a device:

D:\TOOLS\__PocketPC\RemoteTools\build>prun "\SD Card\batterylog" 5 4000
D:\TOOLS\__PocketPC\RemoteTools\build>prun "\SD Card\batterylog" kill

The first line shows how I start the tool, saying ‘do a log every 5 seconds and estimate for a 4000mAh battery’.

In the second line I request the tool to stop running.

Warning: Also one try to estimate the batt lifetime the calculated time may vary and so there is never a waranty for the estimated life time.

Have fun

BTW: here you will find netcat for windows and other infos about netcat:
http://en.wikipedia.org/wiki/Netcat

Downloads:

[Download not found] [Download not found] [Download not found]